<?php

namespace App\Http\Controllers\YApi;

//use Illuminate\Http\Request;
use Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Session;
use Redirect;

use App\Models\Book;
use App\Models\Bags;
use App\Models\BagsLiuyan;
use App\Models\UsersReg;
use App\Models\UsersAttrib;

class ShopinfoController extends Controller
{

  public function shopinfo($bagsid)
    {
        //转让图书的信息
        $bags = Bags::where('id', $bagsid)->first();
        // foreach($bags as $bag)
        // {
            //为了得到图书的信息
            $bags['books'] = Book::find($bags->book_id);
        // }
        // foreach($bags as $bag)
        // {
            //为了得到商品用户的信息
            $bags['users'] = UsersReg::find($bags->uid);
        // }

        // $usersattribs = UsersAttrib::where('uid', $bags[0]['users']->uid)->first();

        //出售商品的留言列表
        $liuyans = BagsLiuyan::where('bagsid', $bagsid)->orderBy('add_time', 'desc')->get();
        if($liuyans != null)
        {
            foreach($liuyans as $liuyan)
            {
                //得到留言用户信息
                $liuyan['users'] = UsersReg::find($liuyan->uid);
            }
        }       

        $bags['liuyans'] = $liuyans;
        
        return $bags;
    } 
    
}